import React from 'react';
import { Table } from 'antd';
import { useResourceColumns, useResourceList } from './hooks';

/**
 * 资源列表
 */
function ResourceList(props) {
    const { taskId, modelId } = props;

    const resourceColumns = useResourceColumns(modelId);
    const resourceList = useResourceList(taskId, modelId);

    return (
        <Table
            rowKey={(_, index) => {
                const { current, pageSize } = resourceList.tableProps.pagination;
                return `${(current - 1) * pageSize + index + 1}`;
            }}
            scroll={{ x: 'max-content' }}
            columns={resourceColumns.data}
            {...resourceList.tableProps}
            loading={resourceColumns.loading || resourceList.tableProps.loading}
            pagination={{
                showSizeChanger: true,
                showTotal: (total) => `共 ${total} 条`,
                ...resourceList.tableProps.pagination,
            }}
        />
    );
}

export default ResourceList;
